package main

import (
	"fmt"
	"net"
	"tcpChat/znet"
	"time"
)

func main() {
	conn, err := net.Dial("tcp", "0.0.0.0:8999")

	if err != nil {
		fmt.Println(err.Error())
	}

	for {

		dp := znet.NewDataPack()

		msg1 := &znet.Message{
			Id:      0,
			DataLen: 5,
			Data:    []byte{'h', 'e', 'l', 'l', 'o'},
		}

		sendData1, err := dp.Pack(msg1)
		if err != nil {
			fmt.Printf("封包错误-1")
		}

		msg2 := &znet.Message{
			Id:      1,
			DataLen: 7,
			Data:    []byte{'w', 'o', 'r', 'l', 'd', '!', '!'},
		}

		sendData2, err := dp.Pack(msg2)
		if err != nil {
			fmt.Printf("封包错误-2")
		}

		//sendData1 = append(sendData1, sendData2...)

		if _, err = conn.Write(sendData1); err != nil {
			fmt.Println(err)
		}

		if _, err = conn.Write(sendData2); err != nil {
			fmt.Println(err)
		}

		time.Sleep(10 * time.Second)
	}

}
